<?php
namespace Home\Controller;
use Think\Controller;
use Utils\RongUtils;
require_once "\Utils\RongUtils.php";
class InfoController extends Controller {
     public function Index(){
         $this->display();
     }
    public function all(){
        if(IS_POST){
            if(RongUtils::pullall($_POST["content"])==200)
            {
                $this->success("发送成功");
                 
            }
            else $this->error("发送失败");

        }
        else
            $this->display();
    }
    public function academy(){
         $m=D("user");
        if(IS_POST){
           $data=$m->where($_POST)->field('student_id')->select();
           $sum= sizeof($data);
           $index=0;
           while(($sum-$index)>0)
           {
            $res[]=array_slice($data, $index, 100);
            $index+=100;
           }
           foreach ($res as $value) {
              foreach ($value as $v) {
                $arr[]=$v["student_id"];
            }
            RongUtils::pullto("院系通知", $arr, $_POST["content"]);
           }
          $this->success("发送成功");
        }
        else
        {
            $data=$m->field('academy')->group('academy')->select();
            $this->assign("list", $data);
            $this->display();
        }
    }
     public function classroom(){
         $m=D("user");
        if(IS_POST){
            $data=$m->where($_POST)->field('student_id')->select();
            foreach ($data as $value) {
                $arr[]=$value["student_id"];
            }
            if(RongUtils::pullto("班级通知", $arr,  $_POST["content"])==200)
            {
                $this->success("发送成功");
             }
             else $this->error("发送失败");

        }
        else
        {
            $data=$m->field('classroom')->select();
            $this->assign("list", $data);
            $this->display();
        }
    }
}